using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MiddlewareServer.Socket;

namespace MiddlewareServer
{
    public class MiddleWare : IServer_rpt, IServer_cmd
    {
        SocketServer mSocket = new SocketServer();
        IServer_rpt mServer;

        public MiddleWare(IServer_rpt a_server)
        {
            mServer = a_server;
            mSocket.Connect();
        }

        # region IServer_rpt Members

        /// <summary>
        /// building connection between client and server using client id
        /// </summary>
        /// <param name="a_uiClientID">client identifier</param>
        public void connect(uint a_uiClientID)
        {
            Console.WriteLine("[MS]::CONNECT from CID:{0}", a_uiClientID);
           // mServer.connect(a_uiClientID);
        }

        /// <summary>
        /// sending client ships board. Declaration of beeng ready by the client
        /// </summary>
        /// <param name="a_uiClientID">client identifier</param>
        /// <param name="a_dtShipsTable">table with ships placement for individual client</param>
        public void ready(uint a_uiClientID, DataTable a_dtShipsTable)
        {
            Console.WriteLine("[MS]::READY from CID:{0}", a_uiClientID);
        }

        /// <summary>
        /// shot performed by client including shot position
        /// </summary>
        /// <param name="a_uiClientID">client identifier</param>
        /// <param name="a_uiXPos">X shot position</param>
        /// <param name="a_uiYPos">Y shot position</param>
        public void shoot(uint a_uiClientID, uint a_uiXPos, uint a_uiYPos)
        {
            Console.WriteLine("[MS]::SHOT from CID:{0}, X = {1}, Y = {2}", a_uiClientID, a_uiXPos, a_uiYPos);
        }

        /// <summary>
        /// destroying connection between client and server using client id
        /// </summary>
        /// <param name="uiClientID">client identifier</param>
        public void disconnect(uint a_uiClientID)
        {
            Console.WriteLine("[MS]::DISCONNECT from CID:{0}", a_uiClientID);
        }
        #endregion

        #region IServer_cmd Members

        /// <summary>
        /// result with connection status or error code 
        /// </summary>
        /// <param name="a_eRetCode">error code enum</param>
        public void connectResult(eReturnErrorCode a_eRetCode)
        {
            Console.WriteLine("[MS]::CONNECT RESULT returnValue:{0}", a_eRetCode);
        }
        /// <summary>
        /// result of client board confirmation
        /// </summary>
        /// <param name="a_uiClientID">client identifier</param>
        /// <param name="a_eRetCode">error code enum</param>
        public void readyResult(uint a_uiClientID, eReturnErrorCode a_eRetCode)
        {
            Console.WriteLine("[MS]::READY RESULT from CID:{0}, returnValue: {1}", a_uiClientID, a_eRetCode);
        }
        /// <summary>
        /// result of client shot
        /// </summary>
        /// <param name="a_uiClientID">client identifier</param>
        /// <param name="a_uiXPos">X shot position</param>
        /// <param name="a_uiYPos">Y shot position</param>
        /// <param name="a_uiShooted"></param>
        public void shootResult(uint a_uiClientID, uint a_uiXPos, uint a_uiYPos, uint a_uiShooted)
        { 
            
        }
        /// <summary>
        /// result of disconnection client from server
        /// </summary>
        /// <param name="a_eRetCode">error code enum</param>
        public void disconnectResult(eReturnErrorCode a_eRetCode)
        { 
            
        }

        #endregion
    }
}
